import { useMovieStore } from '@/common/hox/movieStore'
import { createGlobalStore } from 'hox'
import { useMemo } from 'react'
import { useAppSettingStore } from '../../common/hox/appSettingStore'
import { TicketModeEnum } from '@/utils/enum'

export const [useTicketModeStore, getTicketModeStore] = createGlobalStore(() => {
  const appSetting = useAppSettingStore()
  const {
    schedule: { scheduleSeatInfo },
  } = useMovieStore(store => [
    store.schedule.scheduleSeatInfo,
  ])

  const ticketModeList = useMemo(() => {
    const { model: seatAllowMode } = scheduleSeatInfo || {}
    if (!seatAllowMode) return []
    const appAllowMode = appSetting.ticketMode.length > 0  ? appSetting.ticketMode : [0, 1] as TicketModeEnum[]
    return appAllowMode.filter(mode => seatAllowMode.includes(mode))
  }, [scheduleSeatInfo?.model, appSetting])

  return { ticketModeList }
})